package com.learn.rabbit.base.sender;

import com.learn.rabbit.base.config.ExchangeConfig;
import com.learn.rabbit.base.config.RabbitmqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Producer of system which
 * name of exchange is {@link ExchangeConfig#EXCHANGE_FANOUT} and type of exchange is fanout
 * and Routing Key is {@link RabbitmqConfig#DIRECT_ROUTING_KEY_ONE}
 *
 * @author zhousiqi
 * @version 1.0.0
 * @date 2019/2/26 18:13
 */
@Component
@Slf4j
public class FanoutFirstSender {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息
     *
     * @param uuid    唯一识别码
     * @param message 消息
     */
    public void send(String uuid, Object message) {
        log.info("fanoutFirstSender 发送消息{}", message);
        CorrelationData correlationId = new CorrelationData(uuid);
        // 第一个参数为交换机名称
        // 第二个参数为Routing Key
        // 第三个参数为发送的消息
        // 第四个参数为识别id
        rabbitTemplate.convertAndSend(ExchangeConfig.EXCHANGE_FANOUT, RabbitmqConfig.DIRECT_ROUTING_KEY_ONE, message, correlationId);
    }
}
